import 'package:flutter/material.dart';
import 'package:demo/big_card.dart';
import 'package:demo/random_english_word.dart';
import 'package:provider/provider.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //监听上下文
    var appState = context.watch<RandomEnglishWord>();
    var pair = appState.current; 
    IconData icon;
    if (appState.favorites.contains(pair)) {
      icon = Icons.favorite;
    } else {
      icon = Icons.favorite_border;
    }
    return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('word'),
            SizedBox(height: 10),
            BigCard(pair: pair),
            SizedBox(height: 10),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                // ↓ And this.
                ElevatedButton.icon(onPressed: () {appState.toggleFavorite();},icon: Icon(icon),label: Text('Like'),),
                SizedBox(height: 10),
                ElevatedButton(onPressed: () {appState.getNext();},child: Text('Next'),),
              ],
            ),
          ],
        ),
      );
  }
}

